package Z.dailyExercise._0225;

import javax.naming.LimitExceededException;
import java.util.LinkedList;
import java.util.Queue;

public class _剑指Offer58II左旋转字符串 {

    /**
     * 先后复制
     * @param s
     * @param n
     * @return
     */
    public String reverseLeftWords(String s, int n) {
        StringBuilder res =new StringBuilder()  ;
        for (int i=n;i<s.length();i++){
            res.append(s.charAt(i));
        }

        for (int i = 0; i < n; i++) {
            res.append(s.charAt(i));
        }

        return res.toString();

    }

    /**
     * 借助队列
     * @param s
     * @param n
     * @return
     */
    public String reverseLeftWords1(String s, int n) {
        Queue<Character> queue = new LinkedList<>();

        for (int i=0;i<n;i++){
            queue.add(s.charAt(i));
            s+=queue.poll();
        }

        return s.substring(n,s.length());
    }

    /**
     * 字符串切片 直接出结果
     */

        public String reverseLeftWords3(String s, int n) {
            return s.substring(n, s.length()) + s.substring(0, n);
        }



}
